package info.touret.winecellar.dao.server;

import info.touret.winecellar.userinfo.server.UserInfoFactoryImpl;
import info.touret.winecellar.userinfo.server.domain.UserInfo;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.matcher.Matchers;

/**
 * Created by IntelliJ IDEA.
 * User: touret-a
 * Date: 25/05/11
 * Time: 16:01
 * To change this template use File | Settings | File Templates.
 */
public class DAOModule extends AbstractModule {
    @Override
    protected void configure() {
        bindInterceptor(Matchers.any(),Matchers.annotatedWith(TraceEnabled.class),new TraceEnabledInterceptor());
        bind(UserInfo.class).toProvider(UserInfoFactoryImpl.class);
    }
    
    @Provides
    public User getUser(){
    	User user = null;
    	try{
		user = getUserServiceFactory().getCurrentUser();
    	}catch(Exception e){
    		e.printStackTrace();
    	}
    	return user;
    }
 
    
    @Provides
    public UserService getUserServiceFactory(){
    	return UserServiceFactory.getUserService();
    }
}
